<?php $this->load->view(TEMPLATE_NAME.'/front/header'); ?>
<?php $this->load->view(TEMPLATE_NAME.'/front/side_left'); ?>
<script type="text/javascript" src="<?php echo base_url().'ckeditor/ckeditor.js' ?>"></script>
<script type="text/javascript" src="<?php echo base_url().'ckfinder/ckfinder.js' ?>"></script>
  <script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/jquery-ui.min.js"></script>
<script type="text/javascript" language="javascript">
setInterval('updatetext()','300000');
  $(document).ready(function(){
if(document.getElementById('formcount').value != "")
{
	var i = document.getElementById('formcount').value;
} else {
  var i = 1;
}
$('#add_more').click(function(){
           $('#add_source').append('<div><strong>Name of Source: <span class="purple">Optional</span></strong><br/><input type="text" name="source_name_'+i+'" id="source_name'+i+'"> </div><div class="clear"></div><div><strong>Source Link: <span class="purple">Optional</span></strong><br/><input type="text" name="source_link_'+i+'" id="source_link_'+i+'"> </div>');
            i++;     
			document.getElementById('formcount').value = i;
			        return false; 
        });
		
		});
		
function updatetext()
{
	var newsid = document.getElementById('newsid').value;
	//alert(CKEDITOR.instances['content'].getData().replace(/<[^>]*>/gi, ''));
	var editorcontent = CKEDITOR.instances['content'].getData().replace(/<div[^>]*>/gi, '');
		$.ajax({
        url:'<?php echo site_url('news/update_draft') ?>',
		type: "POST",
        secureuri:false,       
		data: "newsid="+newsid+"&newscontent="+editorcontent,
        success: function (msg){
			if(msg == '1')
			{
				document.getElementById('savingid').style.display = 'none';
			} else {
				document.getElementById('savingid').style.display = 'block';
			}
		},
    });
	
	
	//var editorcontent = CKEDITOR.instances['content'].getData().replace(/<[^>]*>/gi, '');
	//if (editorcontent.length){
		//alert(editorcontent);
//	}
	//else{
		//return false;
	//}

	//var text =  document.getElementById('content').value;
	//alert(text);
}

function checkvalidation()
{
	var article_heading = document.getElementById('article_heading').value;
	if(article_heading == "")
	{
		document.getElementById('articleheaderr').style.display = "block";
		return false;
	} else {
		document.getElementById('articleheaderr').style.display = "none";
	}
	
	 var editorcontent = CKEDITOR.instances['content'].getData().replace(/<[^>]*>/gi, '');
	 if(editorcontent.length == '0')
	 {
		document.getElementById('ckcontenterr').style.display = "block";
		return false;
	} else {
		document.getElementById('ckcontenterr').style.display = "none";
	}
}

</script>
<div class="page">
<h2>Post News </h2>

<!--<div class="clear"></div>-->
<?php $this->load->view(TEMPLATE_NAME.'/front/news_header');
//$insertnewsid = $this->session->userdata('newsid');
//$news_content = $this->News_model->get_all_news($insertnewsid);
?>
<?php
$attributes = array('class' => 'posts longs','onSubmit' => 'return checkvalidation()');
echo form_open('news/news_story', $attributes); 
$categorylist = $this->News_model->news_categorys_list();
$categoryid = $newscontent[0]['category_id'];
//$networklistings = array(''=> '');
if($categorylist)
{
	foreach($categorylist as $key=>$value)
	{
		//$tempnetworklistings[$value[id]] = $value['name'];
		$keys[]=$value[id];
		$values[]=$value['category'];
	}
}
$categorylistings = array_combine($keys,$values);
?>
<!--<div>--><p class="phase"><strong>News Story</strong> - Input your news story - <span class="purple">This page will autosave every 5 mins</span><span id="savingid" style="display:none">Saving......</span></p><!--</div>-->
<!--<div class="clear"></div>
<div class="clear"></div>
<div class="wmap" style="width:100%">
<div>-->
<p class="mb0"><strong class="purple f14">News Category: <sup>*</sup></strong><br />
What Category does this news fit into? This is for easire filtering on news 
stories</p>

<?php  echo form_dropdown('category_list',$categorylistings,$categoryid, ' style="margin-left:0;"'); ?>
<div class="clear"></div>
<p><!--<strong>--><label>Article Heading: <sup>*</sup></label><!--</strong>--><br/>
<?php 
$article_heading_input = array(
	'id'=>'article_heading',
	'name'=>'article_heading',
	'style' => 'width:98%'
	);
	$articlehead = $newscontent[0]['article_heading'];
echo form_input($article_heading_input,$articlehead);
//echo form_error('articleheading','<p class="inform f12 error_message"><strong>Error:</strong>','</p>');?>
</p>
<div class="clear"></div>
<div style="background-color: #9F0; color:#000; text-align:center; display:none" id="articleheaderr">Please enter article title</div>

<!--</div>
<div class="clear"></div>
<div>--> 
<!--<strong>--><label>Article Content: <sup>*</sup></label><!--</strong>--><br/>
<?php
$CI = get_instance();
$CI->load->helper('url');
$CI->load->helper('ckeditor_helper');
$ckeditor = array(
 
			//ID of the textarea that will be replaced
			'id' 	=> 	'content', 	// Must match the textarea's id
			'path'	=>	'ckeditor',	// Path to the ckeditor folder relative to index.php
			'ckfinder' => array(
            'path'    =>    'ckfinder'
 ),
			//Optionnal values
			'config' => array(
				'toolbar' 	=> 	"Full", 	//Using the Full toolbar
				//'width' 	=> 	"600px",	//Setting a custom width
				//'height' 	=> 	'200px',	//Setting a custom height
                'width'     =>  '580px',
                'height'    =>  '300px',
			)
);

$articlecontent = $newscontent[0]['article_description'];
?>
<textarea name="content" id="content"  ><?php echo $articlecontent ?></textarea>
<?php
echo display_ckeditor($ckeditor); ?>
<!--</div>-->
<div class="clear"></div>
<div style="background-color: #9F0; color:#000; text-align:center; display:none" id="ckcontenterr">Please enter article content</div>
<div class="clear"></div>
<!--<div><strong>--><p class="phase">News Source<!--</strong>--> - <span class="purple">If you sourced your information above - please give them credit. <strong>Optional</strong></span></p><!--</div>-->
<?php
//$news_source = $this->News_model->get_source_count($insertnewsid);
//if($news_source > 0)
//{
	//$news_source_content = $this->News_model->get_all_sources($insertnewsid);
//}
?>
<!--<div>-->

	<!--<strong>--><label>Name of Source: <!--<span class="purple">--><sup>Optional</sup></label><!--</span></strong>--><br/>
    <?php 
$source_name_input = array(
	'id'=>'source_name',
	'name'=>'source_name'
	);
$sourcenameval = $sourcecontent[0]['source_name'];
	echo form_input($source_name_input,$sourcenameval);
?> <br />
<!--</div>
<div class="clear"></div>

<div>
	<strong>--><label>Source Link: <!--<span class="purple">--><sup>Optional</sup></label><!--</span></strong>--><br/>
    <?php 
	
$source_link_input = array(
	'id'=>'source_link',
	'name'=>'source_link'
	);
$sourcelinkval = $sourcecontent[0]['source_link'];
	echo form_input($source_link_input,$sourcelinkval);
?>
<!--</div>--><br />
<?php
for($i=1;$i<$sourcecount;$i++)
{
?>
<!--<div>

	<strong>--><label>Name of Source: <!--<span class="purple">--><sup>Optional</sup></label> <!--</span></strong>--><br/>
    <?php 
$source_name_input = array(
	'id'=>'source_name'.$i,
	'name'=>'source_name_'.$i
	);
$sourcenameval = $sourcecontent[$i]['source_name'];
	echo form_input($source_name_input,$sourcenameval);
?><br />
<!--</div>
<div class="clear"></div>

<div>
	<strong>--><label>Source Link: <!--<span class="purple">--><sup>Optional</sup></label><!--</span></strong>--><br/>
    <?php 
	
$source_link_input = array(
	'id'=>'source_link'.$i,
	'name'=>'source_link_'.$i
	);
$sourcelinkval = $sourcecontent[$i]['source_link'];
	echo form_input($source_link_input,$sourcelinkval);
?>
<!--</div> --><br />
<?php
}
?>
<div class="clear"></div>
<div id="add_source"></div>
<!--<div><span class="purple">-->
<strong><a id="add_more" href="#">+ Add another source</a></strong><!--</span>-->
<input type="hidden" name="formcount" id="formcount" value="<?php echo $sourcecount ?>">
  <input type="hidden" name="newsid" id="newsid" value="<?php echo $newscontent[0]['id'] ?>" /><!--</div> -->
<!--<div class="clear"></div>
<div>-->
<hr class="mb0" /><?php echo form_submit('newstory', 'Submit'); ?> <!--</div>-->
<?php echo form_close(); ?> 
<!--</div>-->
    <?php $this->load->view(TEMPLATE_NAME.'/front/footer_menu');?>
</div><!-- page -->

<?php $this->load->view(TEMPLATE_NAME.'/front/side_right');?> 
<?php $this->load->view(TEMPLATE_NAME.'/front/footer');?> 